package com.itheima.day06_api_day01.Test04;

import java.util.ArrayList;
import java.util.Arrays;

public class Test04 {
    /*
        某公司发放年终礼品，但hr在统计的时候发现有很多同姓名同年龄的员工，
        所以决定对这一部分员工，发放【缘分大礼包】，其余员工发放【普通大礼包】，
        请用技术手段，完成礼品的分发。
            现有4个员工信息：
            1. 张三，23
            2. 李四，24
            3. 张三，23
            4. 张三，28
            Employee{name=张三,age=23}获得了缘分大礼包
            Employee{name=李四,age=24}获得了普通大礼包
            Employee{name=张三,age=23}获得了缘分大礼包
            Employee{name=张三,age=28}获得了普通大礼包
     */
    public static void main(String[] args) {

        Employee e1 = new Employee("张三", 23);
        Employee e2 = new Employee("李四", 24);
        Employee e3 = new Employee("张三", 23);
        Employee e4 = new Employee("张三", 28);
        ArrayList<Employee> arr = new ArrayList<>();
        arr.add(e1);
        arr.add(e2);
        arr.add(e3);
        arr.add(e4);

        method(arr);

    }

    public static void method(ArrayList<Employee> arr){

        for (int i = 0; i < arr.size(); i++) {
            boolean flag = false;
            Employee e1 = arr.get(i);
            for (int j = 0; j < arr.size(); j++) {
                Employee e2 = arr.get(j);
                if(e1 != e2 && e1.equals(e2)){
                    flag = true;
               }
            }
            if(flag){
                System.out.println(e1+"缘分大礼包");
            }else{
                System.out.println(e1+"普通大礼包");
            }
        }
    }

}

class Employee {
    private String name;
    private int age;
    private String grade="普通大礼包";

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Employee employee = (Employee) o;

        if (age != employee.age) return false;
        if (name != null ? !name.equals(employee.name) : employee.name != null) return false;
        return grade != null ? grade.equals(employee.grade) : employee.grade == null;

    }

    public Employee() {
    }

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }
}